<template>
	<div class="me">
		<master-msg v-if="$store.state.isMaster"/>
		<my-info v-else :isOper="isOper"/>
		<consult :lists="consultList" :cls="''" :type="'3'"/>
		<consult :lists="orderList" :cls="''" :type="'1,2'"/>
		<!-- <consult :lists="luckList" :cls="'xicon'" v-if="!$store.state.isMaster"/> -->
		<my-operation :operList="operList"/>
		<m-footer />
	</div>
</template>

<script>
	import mFooter from "@/components/footer"; // 底部导航
	import myInfo from "@/components/myInfo.vue"; // 普通用户个人信息
	import masterMsg from '@/components/masterInfo/masterMsg'; // 大师个人信息
	import consult from "@/components/consult.vue"; // 订单
	import myOperation from "@/components/myOperation"; // 
	export default {
		components: {
			mFooter,
			myInfo,
			masterMsg,
			consult,
			myOperation,
		},
		data() {
			return {
				isOper: false,
				consultList: {
					title: "咨询订单",
					path: "",
					list: [
						
					]
				},
				orderList: {
					title: "闪问•闪答",
					path: "",
					list: [
						
					]
				},
				luckList: {
					title: "开运订单",
					path: "/orderform?type=4&key=0",
					list: [
						{
							name: "代付款",
							img: "fukuan",
							path: "/orderform?type=4&key=3"
						},
						{
							name: "代发货",
							img: "daifahuo",
							path: "/orderform?type=4&key=3"
						},
						{
							name: "已发货",
							img: "yifahuo",
							path: "/orderform?type=4&key=3"
						},
						{
							name: "待收货",
							img: "daishouhuo",
							path: "/orderform?type=4&key=3"
						},
						{
							name: "已完成",
							img: "success",
							path: "/orderform?type=4&key=3"
						}
					]
				},
				operList:{
					list: [

					]
				}
			};
		},
		created(){
			this.ifMaster()
		},
		methods: {
			ifMaster() {
				if(this.$store.state.isMaster) {
					this.consultList = {
						title: "咨询订单",
						path: "/masterOrder?type=3&key=0",
						list: [
							{
								name: "待确认",
								img: "daiqueren",
								path: "/masterOrder?type=3&key=2"
							},
							{
								name: "待解答",
								img: "daijieda",
								path: "/masterOrder?type=3&key=2"
							},
							{
								name: "进行中",
								img: "jinxingzhong",
								path: "/masterOrder?type=3&key=3"
							},
							{
								name: "已完成",
								img: "yiwancheng",
								path: "/masterOrder?type=3&key=5"
							}
						]
					};
					this.orderList = {
						title: "闪问•闪答",
						path: "/masterOrder?type=1,2&key=0",
						list: [
							{
								name: "待确认",
								img: "daiqueren",
								path: "/masterOrder?type=1,2&key=2"
							},
							{
								name: "待回复",
								img: "dingdan",
								path: "/masterOrder?type=1,2&key=8"
							},
							{
								name: "进行中",
								img: "jinxingzhong",
								path: "/masterOrder?type=1,2&key=3"
							},
							{
								name: "已完成",
								img: "yiwancheng",
								path: "/masterOrder?type=1,2&key=5"
							}
						]
					};
					this.operList = {
						list: [
							{
								name: '我的收入',
								img: 'zhangdan',
								path: '/bill'
							},
							{
								name: '收藏商品',
								img: 'shoucang',
								path: '' // /collectgoods
							},
							{
								name: '成为运营商',
								img: 'yunying',
								path: '/partner'
							},
							{
								name: '推荐好友',
								img: 'tuijian',
								path: '/recommend'
							},
							{
								name: '我的服务',
								img: 'fuwu',
								path: '/myService'
							},
							{
								name: '我的粉丝',
								img: 'fensi',
								path: '/fans'
							},
							{
								name: '联系客服',
								img: 'kefu',
								path: '/service'
							},
							{
								name: '设置',
								img: 'shezhi',
								path: '/setting'
							},
						]
					}
					this.isOperator('master')
				} else {
					this.consultList = {
						title: "咨询订单",
						path: "/orderform?type=3&key=0",
						list: [
							{
								name: "待付款",
								img: "daifukuan",
								path: "/orderform?type=3&key=1"
							},
							{
								name: "进行中",
								img: "jinxingzhong",
								path: "/orderform?type=3&key=3"
							},
							{
								name: "待评价",
								img: "daipingjia",
								path: "/orderform?type=3&key=4"
							}
						]
					};
					this.orderList = {
						title: "闪问•闪答",
						path: "/orderform?type=1,2&key=0",
						list: [
							{
								name: "待回复",
								img: "dingdan",
								path: "/orderform?type=1,2&key=8"
							},
							{
								name: "已完成",
								img: "yiwancheng",
								path: "/orderform?type=1,2&key=5"
							},
							{
								name: "已取消",
								img: "yiqvxiao",
								path: "/orderform?type=1,2&key=9"
							}
						]
					};
					this.operList = {
						list: [
							{
								name: '我的关注',
								img: 'guanzhu',
								path: '/attention'
							},
							{
								name: '收藏商品',
								img: 'shoucang',
								path: '' ///collectgoods
							},
							{
								name: '我的优惠券',
								img: 'youhui',
								path: '/discountCoupon'
							},
							{
								name: '推荐好友',
								img: 'tuijian',
								path: '/recommend'
							},
							{
								name: '认证大师',
								img: 'renzheng',
								path: '/approve'
							},
							{
								name: '成为运营商',
								img: 'yunying',
								path: '/partner'
							},
							{
								name: '联系客服',
								img: 'kefu',
								path: '/service'
							},
							{
								name: '设置',
								img: 'shezhi',
								path: '/setting'
							},
						]
					}
					if(this.$store.state.masterId){
						this.operList.list.splice(4, 1)
					}
					this.isOperator('user')
				}
			},
			isOperator(m) {
				let params = {
					userId: this.$store.state.userId
				}
				this.$http.fetchGet('isOperator', params).then(res => {
					if(res.code == 200) {
						if(res.data.operator_id != 0) {
							this.isOper = true
							this.operList.list.map((val, ind) => {
								if(val.name == '成为运营商' && m == 'user') {
									this.operList.list[ind].name = '我的收入'
									this.operList.list[ind].img = 'zhangdan'
									this.operList.list[ind].path = '/bill'
								} else if(val.name == '成为运营商' && m == 'master') {
									this.operList.list[ind].name = '运营商管理'
									this.operList.list[ind].img = '用户数'
									this.operList.list[ind].path = '/myClient'
								}
							})
						}
					} else {
						console.log(res.msg)
					}
				}, err => {
					console.log(err)
				})
			},
			getStorages() {
				let nowTime = new Date();
				let times2 = `${nowTime.getFullYear()}-${nowTime.getMonth()}-${nowTime.getDate()}`
				let times3 = new Date(times2).getTime()
				let storage = window.localStorage;
				let rec = JSON.parse(storage.getItem('record'));
				if(rec) {
					for(let key in rec) {
						rec[key].map(function(val, ind) {
							if (times3 - val.time > 86400000) {
								rec[key].splice(ind, 1)
							} else {

							}
						})
					}
				} else {
					storage.setItem("record", JSON.parse(JSON.stringify(rec)) ? JSON.stringify(rec) : '{}');
				}
			}
		},
		mounted() {
			this.getStorages();
		}
	};
	</script>

<style lang="less" scoped>
.me {
  .pb(@fheight);
  background: #f2f2f2;
}
</style>
